//
//  HistoryDetailViewController.swift
//  BookStore
//
//  Created by JinYuXin on 2022/5/14.
//

import UIKit

class HistoryDetailViewController: UIViewController,UITableViewDataSource {

    

    @IBOutlet weak var price: UILabel!
    @IBOutlet weak var books: UILabel!
    @IBOutlet weak var num: UILabel!
    @IBOutlet weak var time: UILabel!
    @IBOutlet weak var listid: UILabel!
    var listtime:String=""
    var bookprice:String=""
    var booknum:String=""
    var listid0:String=""
    var booksid:String=""
    var bookidarr=[String]()
    override func viewDidLoad() {
        super.viewDidLoad()
        bookidarr = booksid.components(separatedBy: ",")
        price.text = bookprice
        num.text = booknum
        time.text = listtime
        listid.text = listid0

        // Do any additional setup after loading the view.
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return bookidarr.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell:UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
        
        cell.detailTextLabel?.text = getBookprice(bookid: bookidarr[indexPath.row])
        cell.textLabel?.text = getBookname(bookid: bookidarr[indexPath.row])
        let pic = getBookpic(bookid: bookidarr[indexPath.row])
        cell.imageView!.downloadAsyncFrom(url: pic)
        tableView.rowHeight = 100
        return cell
    }
    
    func getBookname(bookid:String)->String
    {

        let querybooktitle = BookTable.getBookInfo(bookid)
        let booktitle = querybooktitle![0] as! [String:String]
        let bookname = booktitle["title"]!

        return bookname
    }
    func getBookpic(bookid:String)->String
    {

        let querybooktitle = BookTable.getBookInfo(bookid)
        let booktitle = querybooktitle![0] as! [String:String]
        let bookname = booktitle["pic"]!

        return bookname
    }
    func getBookprice(bookid:String)->String
    {

        let querybooktitle = BookTable.getBookInfo(bookid)
        let booktitle = querybooktitle![0] as! [String:String]
        let bookname = booktitle["price"]!

        return bookname
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
